<template>
  <el-dialog
    v-loading="loading"
    :visible.sync="dialog"
    :close-on-click-modal="false"
    title="审核详情"
    width="85%"
  >
    <div style="padding-top:20px">
      <div style="float:right;margin-bottom:5px;">
        <el-button size="mini" type="primary" icon="el-icon-circle-check" round @click="batchAgree">批量同意</el-button>
        <el-button size="mini" type="primary" icon="el-icon-circle-close" round @click="batchReject">批量驳回</el-button>
      </div>
      <el-table ref="itemTab" :data="data" stripe size="small" border style="width: 100%;" @header-dragend="colChange">
        <el-table-column :show-overflow-tooltip="true" label="条码" prop="upcNbr" :width="colWidths.upcNbr" />
        <el-table-column :show-overflow-tooltip="true" label="供应商名称" prop="vendorName" :width="colWidths.vendorName" />
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="商品说明1" prop="buyerItem1Desc" :width="colWidths.buyerItem1Desc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItem1Desc !== scope.row.vendorItem1Desc ? 'color:#fc1111' : ''">{{ scope.row.buyerItem1Desc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="商品说明1" prop="vendorItem1Desc" :width="colWidths.vendorItem1Desc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItem1Desc !== scope.row.vendorItem1Desc ? 'color:#fc1111' : ''">{{ scope.row.vendorItem1Desc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="较长商品说明" prop="buyerItem1DescLength" :width="colWidths.buyerItem1DescLength">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItem1DescLength !== scope.row.vendorItem1DescLength ? 'color:#fc1111' : ''">{{ scope.row.buyerItem1DescLength }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="较长商品说明" prop="vendorItem1DescLength" :width="colWidths.vendorItem1DescLength">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItem1DescLength !== scope.row.vendorItem1DescLength ? 'color:#fc1111' : ''">{{ scope.row.vendorItem1DescLength }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="供应商之商品代码" prop="buyerVendorStockId" :width="colWidths.buyerVendorStockId">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVendorStockId !== scope.row.vendorStockId ? 'color:#fc1111' : ''">{{ scope.row.buyerVendorStockId }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="供应商之商品代码" prop="vendorStockId" :width="colWidths.vendorStockId">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVendorStockId !== scope.row.vendorStockId ? 'color:#fc1111' : ''">{{ scope.row.vendorStockId }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="规格型号" prop="buyerShlflbl3SizeDesc" :width="colWidths.buyerShlflbl3SizeDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl3SizeDesc !== scope.row.vendorShlflbl3SizeDesc ? 'color:#fc1111' : ''">{{ scope.row.buyerShlflbl3SizeDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="规格型号" prop="vendorShlflbl3SizeDesc" :width="colWidths.vendorShlflbl3SizeDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl3SizeDesc !== scope.row.vendorShlflbl3SizeDesc ? 'color:#fc1111' : ''">{{ scope.row.vendorShlflbl3SizeDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <!-- <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="货架2/规格" prop="buyerShlflbl2SizeDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl2SizeDesc !== scope.row.vendorShlflbl2SizeDesc ? 'color:#fc1111' : ''">{{ scope.row.buyerShlflbl2SizeDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="货架2/规格" prop="vendorShlflbl2SizeDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl2SizeDesc !== scope.row.vendorShlflbl2SizeDesc ? 'color:#fc1111' : ''">{{ scope.row.vendorShlflbl2SizeDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column> -->
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="货架1/颜色" prop="buyerShlflbl1ColrDesc" :width="colWidths.buyerShlflbl1ColrDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl1ColrDesc !== scope.row.vendorShlflbl1ColrDesc ? 'color:#fc1111' : ''">{{ scope.row.buyerShlflbl1ColrDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="货架1/颜色" prop="vendorShlflbl1ColrDesc" :width="colWidths.vendorShlflbl1ColrDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl1ColrDesc !== scope.row.vendorShlflbl1ColrDesc ? 'color:#fc1111' : ''">{{ scope.row.vendorShlflbl1ColrDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="产地" prop="buyerMdsDesc" :width="colWidths.buyerMdsDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerMdsDesc !== scope.row.vendorMdsDesc ? 'color:#fc1111' : ''">{{ scope.row.buyerMdsDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="产地" prop="vendorMdsDesc" :width="colWidths.vendorMdsDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerMdsDesc !== scope.row.vendorMdsDesc ? 'color:#fc1111' : ''">{{ scope.row.vendorMdsDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="供应商包装成本" prop="buyerVnpkCostAmt" :width="colWidths.buyerVnpkCostAmt" />
        <el-table-column label="采购附件" prop="filePath" :width="colWidths.buyerFilePath">
          <template slot-scope="scope">
            <i v-if="scope.row.buyerFilePath" class="el-icon-picture" style="font-size:23px;margin-right: 3px;" @click="previewFile(scope.row.buyerFilePath)" />
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="提交时间" prop="updatedTime" :width="colWidths.updatedTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updatedTime) }}</span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <el-pagination
        :total="total"
        :current-page.sync="currentPage"
        :page-sizes="[10,50,100,500]"
        style="margin-top: 8px;"
        layout="total, prev, pager, next, sizes"
        @size-change="sizeChange"
        @current-change="pageChange"
      />
    </div>
  </el-dialog>
</template>

<script>
import { parseTime } from '@/utils/index'
import { Message } from 'element-ui'
import initData from '@/utils/initData'
import { batchItemFileAuditAgree, batchItemFileAuditReject } from '@/api/new-item'
import { previewFile } from '@/utils/item'

export default {
  mixins: [initData],
  props: {
    parent: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      loading: false,
      dialog: false,
      batchRecordId: ''
    }
  },
  methods: {
    parseTime,
    previewFile,
    beforeInit() {
      this.url = '/new-item/itemFileAuditList'
      this.params.pageNum = this.page
      this.params.pageSize = this.size
      this.params.batchRecordId = this.batchRecordId
      return true
    },
    // 查询
    toQuery() {
      this.page = 0
      this.currentPage = 1
      this.init()
    },
    // 批量同意触发
    batchAgree() {
      this.$confirm('确认审核通过该批item信息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        batchItemFileAuditAgree(this.batchRecordId).then(res => {
          this.parent.toQuery()
          Message({
            message: '审核完成。',
            type: 'success',
            duration: 3 * 1000
          })
          this.loading = false
          this.dialog = false
        }, error => {
          console.log(error)
          this.loading = false
        })
      })
    },
    // 批量审核驳回
    batchReject() {
      this.$prompt('请输入驳回原因', '确认审核驳回该批item信息？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValidator: this.rejectRemarkValidator,
        type: 'warning'
      }).then((rejectRemark) => {
        this.loading = true
        batchItemFileAuditReject(this.batchRecordId, rejectRemark.value).then(res => {
          this.parent.toQuery()
          Message({
            message: '审核完成。',
            type: 'success',
            duration: 3 * 1000
          })
          this.loading = false
          this.dialog = false
        }, error => {
          console.log(error)
          this.loading = false
        })
      })
    },
    rejectRemarkValidator(val) {
      if (!val) {
        return '请填写驳回原因'
      } else if (val.length > 500) {
        return '驳回原因长度为1-500'
      }
      return true
    }
  }
}
</script>
